package control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.javafx.image.IntPixelGetter;

import dao.Dao;
import model.Page;


@WebServlet(name="main",urlPatterns={"/main"})
public class QuanMain extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public QuanMain() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String str=request.getParameter("type");
		System.out.println(request.getParameter("type"));
		
		System.out.println(request.getRequestURI());
	//	System.out.println(request.getParameter("type"));
		//System.out.println(t);
	
		int type=Integer.parseInt(str);
		Dao d=new Dao();
		Page[] list;
		if(type==0){
			list=d.readAll(0);
		}else{
			list=d.read(type, 0);
		}
		
		request.getSession().setAttribute("list", list);
		request.getRequestDispatcher("/WEB-INF/main.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
